package com.example.administrator.zdtumblr_android_new.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;


import com.example.administrator.zdtumblr_android_new.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/3/24 0024.
 */

public class MainRecycleAdapter extends RecyclerView.Adapter<MainRecycleHolder> {

    private LayoutInflater inflater;
    private Context mContext;
    private MainRecycleItemAdapter adapter;

    public MainRecycleAdapter(Context mContext) {
        this.inflater = LayoutInflater.from(mContext);
        this.mContext = mContext;
    }

    @Override
    public MainRecycleHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MainRecycleHolder holder = new MainRecycleHolder(inflater.inflate(R.layout.adapter_main_recycle_item, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MainRecycleHolder holder, final int position) {
        if (position == 9) {
            holder.itemFootView.setVisibility(View.GONE);
        }
        holder.itemTipsRecycle.getParent().requestDisallowInterceptTouchEvent(true);
        holder.itemTipsRecycle.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
        adapter = new MainRecycleItemAdapter(mContext);
        holder.itemTipsRecycle.setAdapter(adapter);

        holder.itemBtnDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(mContext,"dianji"+position,Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public int getItemCount() {
        return 10;
    }
}

class MainRecycleHolder extends RecyclerView.ViewHolder {
    @Bind(R.id.item_foot_view)
    View itemFootView;
    @Bind(R.id.item_tips_recycle)
    RecyclerView itemTipsRecycle;
    @Bind(R.id.item_btn_delete)
    Button itemBtnDelete;

    public MainRecycleHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);
    }
}